package com.oauth.service.impl;

import com.oauth.mapper.OpenClientMapper;
import com.oauth.model.OpenClient;
import com.oauth.service.OpenClientService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

/**
 * Created by yangjianbo on 2016/9/29.
 */
@Service
public class OpenClientServiceImpl implements OpenClientService {

    @Autowired
    private OpenClientMapper openClientMapper;

    @Override
    public Boolean isExisted(String client_id) {
        OpenClient openClient=openClientMapper.selectByPrimaryKey(client_id);
        return openClient==null?false:true;
    }

    @Override
    public Boolean isUsed(String client_id) {
        OpenClient openClient=openClientMapper.selectByPrimaryKey(client_id);
        if(openClient==null){
            return false;
        }else if(openClient.getClientStatus().equals(0)){
            return true;
        }else {
            return false;
        }
    }

    @Override
    public Boolean isMatched(String client_id, String client_secret) {
        OpenClient openClient=openClientMapper.selectByPrimaryKey(client_id);
        if(openClient==null){
            return false;
        }else if(openClient.getClientSecure().equals(client_secret)){
            return true;
        }else {
            return false;
        }
    }
}
